using System;
using System.Collections.Generic;
using Xunit.Abstractions;

#if XUNIT_CORE_DLL

namespace Xunit.Sdk
#else
namespace Xunit
#endif
{
	/// <summary>
	/// Default implementation of <see cref="IErrorMessage"/>.
	/// </summary>
	public class ErrorMessage : LongLivedMarshalByRefObject, IErrorMessage
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="ErrorMessage"/> class.
		/// </summary>
		public ErrorMessage(IEnumerable<ITestCase> testCases, string[] exceptionTypes, string[] messages, string[] stackTraces, int[] exceptionParentIndices)
		{
			TestCases = testCases;
			StackTraces = stackTraces;
			Messages = messages;
			ExceptionTypes = exceptionTypes;
			ExceptionParentIndices = exceptionParentIndices;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ErrorMessage"/> class.
		/// </summary>
		public ErrorMessage(IEnumerable<ITestCase> testCases, Exception ex)
		{
			TestCases = testCases;

			var failureInfo = ExceptionUtility.ConvertExceptionToFailureInformation(ex);
			ExceptionTypes = failureInfo.ExceptionTypes;
			Messages = failureInfo.Messages;
			StackTraces = failureInfo.StackTraces;
			ExceptionParentIndices = failureInfo.ExceptionParentIndices;
		}

		/// <inheritdoc/>
		public string[] ExceptionTypes { get; private set; }

		/// <inheritdoc/>
		public string[] Messages { get; private set; }

		/// <inheritdoc/>
		public string[] StackTraces { get; private set; }

		/// <inheritdoc/>
		public int[] ExceptionParentIndices { get; private set; }

		/// <inheritdoc/>
		public IEnumerable<ITestCase> TestCases { get; private set; }
	}
}